<template>
    <div>
        <iframe v-if="iframeVisible" class="notice-iframe" :src="iframeSrc" frameborder="0"
            allow="autoplay;microphone;camera;midi;encrypted-media" />
    </div>
</template>

<script>
export default {
    model: {
        prop: 'iframeVisible', // 默认是value
        event: 'input', // 默认是input
    },
    props: {
        iframeVisible: {
            type: Boolean,
            default: () => false
        },
        dictId: {
            type: [String, Number],
            required: true
        },
        keyId: {
            type: [String, Number],
        },
        noticeId: {
            type: [String, Number],
        },
        archivesId: {
            type: [String, Number],
        },
        currentIndex: {
            type: [String, Number],
            required: true
        },
        pdfDownload: {
            type: Boolean,
            default: false
        },
        isEdit: {
            type: Boolean,
            default: false
        }
    },
    computed: {
        iframeSrc() {
            // 1.现场公告,2.询问笔录 3：物品清单 4：勘验笔录 5：现场平面图 6：环境勘验 7：初步勘验  8：细项勘验  9：专项勘验  10：证据材料 11 损失清单
            const obj = {
                1: 'add',
                2: 'penrecord',
                3: 'inventory',
                4: 'inquest',
                5: 'add',
                6: 'add',
                7: 'add',
                8: 'add',
                9: 'add',
                10: 'loss',
                11: 'add',
                12: 'add',
                13: 'add',
                14: 'minorFire',
                16: 'videolist',
                17: 'imageAssociation'
            }
            console.log(`${process.env.VUE_APP_H5_API}/${obj[this.dictId]}?token=${this.$store.getters.token}&dictId=${this.dictId}&noticeId=${this.noticeId}&archivesId=${this.archivesId}&keyId=${this.keyId}&currentIndex=${this.currentIndex}&nickName=${this.$store.state.user.nickName}&userId=${this.$store.getters.userInfo.userId}&pdfDownload=${this.pdfDownload}`);

            return `${process.env.VUE_APP_H5_API}/${obj[this.dictId]}?token=${this.$store.getters.token}&dictId=${this.dictId}&noticeId=${this.noticeId}&archivesId=${this.archivesId}&keyId=${this.keyId}&currentIndex=${this.currentIndex}&nickName=${this.$store.state.user.nickName}&userId=${this.$store.getters.userInfo.userId}&pdfDownload=${this.pdfDownload}`
        },
    },
    created() {
        window.addEventListener('message', this.receiveMessage)
    },
    destroyed() {
        console.log('destroyed');
        window.removeEventListener(
            'message',
            this.receiveMessage
        )
    },
    methods: {
        receiveMessage(event) {
            this.$emit('message', event)
        },
    }
}
</script>
<style scoped></style>